package com.merry.jedis.demo;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.Transaction;

import java.util.List;
import java.util.Set;

/**
 * @author msi
 * jedis 测试类
 */
public class JedisDemo {
    public static void main(String[] args) {
        //1. 通过指定IP和端口号获取 connection。
        Jedis jedis = new Jedis("139.159.217.216", 6379);

        //2.指定访问服务器的密码
//        jedis.auth("111111");
        //3.获得了 jedis客户端，可以像jdbc一样，访问我们的jedis。
        System.out.println(jedis.ping());

        //keys
        Set<String> keys = jedis.keys("*");
        System.out.println(keys);

        //string
        jedis.set("k3","hello-jedis");
        System.out.println(jedis.get("k3"));
        System.out.println(jedis.ttl("k3"));

        //list
        jedis.lpush("list","11,12,13");
        List<String> list = jedis.lrange("list", 0, -1);
        for (String element : list){
            System.out.println(element);
        }

        //事务 multi
        Transaction multi = jedis.multi();
        multi.set("k1","v1");
        multi.hset("hash1","k2","v2");
        multi.exec();


    }

}
